# -*- coding: UTF-8 -*-
import mysql.connector
import db
    

db_conn = db.DB_Con()
# Conn().execute("SHOW DATABASES")
# for x in mycursor:
#   print(x)
def testConn( ):
    "测试连接"
    mycursor = db_conn.mydb.cursor()
    mycursor.execute("SELECT * FROM touch_message")
    myresult = mycursor.fetchall()
    for x in myresult:
        print(x)
    return;
testConn()

def insertDemo( ):
    "mysql 连接insert测试"
    class Drug_ins_dict:
        #定义基本属性
        id =''
        name =   ''
    drug_ins_dict_list = []
    fs = open("D:\duizhao_down.txt", "r")
    i = 0
    for f in fs:
        lineArr =f.strip().split('\t')
        d = Drug_ins_dict()
        d.id = lineArr[0]
        d.name = lineArr[1]
        drug_ins_dict_list.append(d)
        i= i+1
        # if i>10000:
        #     break
    fs.close()
    mycursor = db_conn.jims_db.cursor()
    sql = "INSERT INTO drug_ins_dict (id,drug_code,drug_name,org_id) VALUES (%s, %s,%s, %s)"
   
    for d1 in drug_ins_dict_list:
        print(d1.id +' -- '+d1.name)
        val = (d1.id,d1.id,d1.name, "21")
        mycursor.execute(sql, val)
    db_conn.jims_db.commit()
    return;

# insertDemo()

def insertDrug( ):
    "mysql 连接insert drug_ins_dict"
    class Drug_ins_dict:
        #定义基本属性
        id =''
        name =   ''
    drug_ins_dict_list = []
    fs = open("C:\\Users\\syl\\Desktop\\pythonLearn\\data\\该部分目录将在2019年12月31日停用.xlsx", encoding='gb18030', errors='ignore')
    i = 0
    for f in fs:
        lineArr =f.strip().split('\t')
        d = Drug_ins_dict()
        d.id = lineArr[0]
        d.name = lineArr[1]
        print(d)
        drug_ins_dict_list.append(d)
        i= i+1
        if i>100:
            break
    fs.close()
    # mycursor = db_conn.jims_db.cursor()
    # sql = "INSERT INTO drug_ins_dict (id,drug_code,drug_name,org_id) VALUES (%s, %s,%s, %s)"
   
    # for d1 in drug_ins_dict_list:
    #     print(d1.id +' -- '+d1.name)
    #     val = (d1.id,d1.id,d1.name, "21")
    #     mycursor.execute(sql, val)
    # db_conn.jims_db.commit()
    return;
insertDrug()

# 
# print(db_conn.jims_db_desc)